#include "SpriteAnimation.h"

SpriteAnimation::SpriteAnimation(){
    timer = animationDelay = 20;
    frameIndex = 0;
}
SpriteAnimation::~SpriteAnimation(){}
void SpriteAnimation::Deinitialize(){
    for(int i = 0; i < frames.size(); i++)
        destroy_bitmap(frames.at(i));    
}
void SpriteAnimation::SetAnimationDelay(unsigned int delay){
    animationDelay = delay;
}
void SpriteAnimation::PushFrame(BITMAP* image){
    frames.push_back(image);
}
void SpriteAnimation::Update(){
    //decrement the timer and go to the next frame
    if(--timer <= 0){
        timer = animationDelay;
        frameIndex = (frameIndex + 1) % frames.size();
    }
    
}
BITMAP* SpriteAnimation::GetCurrentFrame(){
    return frames.at(frameIndex);
}